/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tp2pdf.pasfait.cart.bean;

import java.util.ArrayList ;
import java.util.List ;
import javax.ejb.Remove;
import javax.ejb.Stateful ;


/**
 *
 * @author Danicela
 */


    @Stateful
    public class CartBean implements Cart {

        String customerName;
        String customerId;
        List<String> contents;

        @Override
        public void initialize(String person) throws BookException {
            if (person == null) {
                throw new BookException("Null person not allowed . ");
            } else {
                customerName = person;
            }
            customerId = "0";
            contents = new ArrayList<String>();
        }

        @Override
        public void initialize(String person, String id) throws BookException {
            if (person == null) {
                throw new BookException("Null person not allowed . ");
            } else {
                customerName = person;
            }
            
            contents = new ArrayList<String>();
        }

        public void addBook(String title) {
            contents.add(title);
        }

        public void removeBook(String title) throws BookException {
            boolean result = contents.remove(title);
            if (result == false) {
                throw new BookException(title + " not in cart . ");
            }
        }

        public List<String> getContents() {
            return contents;
        }

        @Remove
        public void remove() {
            contents = null;
        }
    }
    

